﻿Public Class frmNuevaNotificación
    Dim dsCaser As caserDataSet
    Dim idNot As Integer
   

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub


    Private Function validar() As Boolean
        Dim valido = True
        Dim sError = ""
        If txtMensaje.Text = "" Then
            valido = False
            sError = "El campo mensaje no puede ser vacio" & vbCrLf
        End If


        If sError <> "" Then
            MessageBox.Show(sError, "Datos Incorrectos", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        Return valido
    End Function

    Private Sub Limpiar()
        txtMensaje.Clear()
    End Sub

    Private Sub btnCrear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCrear.Click
        If (validar()) Then
            dsCaser.notificaciones.AddnotificacionesRow(dtpFecha.Value, txtMensaje.Text, idNot, Principal.rowlogin.id)
            Dim sError As String = ""

            sError = GuardarTabla(dsCaser.notificaciones)

            If sError <> "" Then
                MessageBox.Show(sError, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)

            Else
                If Me.MdiParent IsNot Nothing Then
                    CType(Me.MdiParent, Principal).Estado = "Notificación registrada..."
                End If
                Limpiar()
                If Me.MdiParent IsNot Nothing Then
                    CType(Me.MdiParent, Principal).contarNotificaciones()
                End If
                Me.Close()

                End If

        End If
    End Sub

    Private Sub frmNuevaNotificación_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dsCaser = New caserDataSet
        If Me.Tag IsNot Nothing Then
            Dim lista(2) As Object
            lista = Me.Tag
            idNot = lista(0)
            txtMensaje.Text = lista(1)
        Else
            idNot = 0

        End If
    End Sub
End Class